var express = require('express');
var router = express.Router();
var formidable = require("formidable")
var fs = require("fs")
const { addInfo, getAllshare, getAllshareorfromname } = require("../controll/infoshares_controll")

router.post('/add', addInfo);
router.post('/contentpage', getAllshare);
router.post('/contentall', getAllshareorfromname);
//上传头像
router.post("/upload", (req, res) => {
    const form = formidable({ multiples: false });
    form.uploadDir = "./public/upload/"//设置上传路径
    form.parse(req, (err, fields, files) => {
        if (!files.file) return;//没有上传文件
        fs.renameSync(files.file.path, form.uploadDir + files.file.name);
        res.json({
            status: 0,
            path: "/upload/" + files.file.name
        })
    })
})
module.exports = router;
